package com.gmall.service;


import com.gmall.mapper.DauMapper;
import com.gmall.mapper.OrderMapper;
import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Title：业务数据服务层实现
 * @Description: [功能描述]
 * @author <a href="mail to: 1034652894@qq.com" rel="nofollow">Demik Qin</a>
 * @CreateDate: 2020/10/17 10:58</p>
 * @update: [序号][日期YYYY-MM-DD] [更改人姓名][变更描述]
 */
@Service
public class PublisherServiceImp implements PublisherService {

    @Autowired
    private DauMapper dau;
    @Autowired
    private OrderMapper order;

    @Override
    public Long getDauTotal(String date) {
        return dau.getDauTotal(date);
    }

    @Override
    public Long getNewMidTotal(String date) {
        return dau.getNewMidTotal(date);
    }

    @Override
    public Map<String, Long> getHourDau(String date) {
        List<Map<String, Object>> hourDau = dau.getHourDau(date);
        Map<String, Long> result = new HashMap<>();

        for (Map<String, Object> map : hourDau) {
            String hour = String.valueOf(map.get("LOGHOUR"));
            Long count = (Long) map.get("COUNT");
            result.put(hour, count);
        }
        return result;
    }

    @Override
    public BigDecimal getTotalAmount(String date) {
        return order.getTotalAmount(date);
    }

    @Override
    public Map<String, BigDecimal> getHourTotalAmount(String date) {
        List<Map<String, Object>> hourAmount = order.getHourTotalAmount(date);
        Map<String, BigDecimal> result = new HashMap<>();
        for (Map<String, Object> map : hourAmount) {
            String hour = (String) map.get("CREATE_HOUR");
            BigDecimal amount = (BigDecimal) map.get("TOTAL_AMOUNT");
            result.put(hour, amount);
        }
        return result;
    }
}
